<?php
/**
 * Created by PhpStorm.
 * User: 64
 * Date: 2017/3/23 0023
 * Time: 14:26
 */
namespace app\web\controller;
use app\src\seller\helper\AddressHelper;
use app\src\sellerCategory\logic\SellerCategoryLogic;
use app\web\api\AccountScoreApi;
use app\src\platform\emnu\PlatformType;
use app\src\seller\logic\SellerLogic;
use app\src\seller\logic\SellerOrderLogic;
use app\src\deleteApply\logic\DeleteApplyLogic;
use app\src\user\action\LoginAction;
use app\web\api\SellerApi;
use app\web\api\InviteCodeApi;
use app\web\api\PlatfromApi;
use app\src\user\logic\UcenterMemberLogic;
use app\src\seller\logic\SellerPromotionLogic;
use app\src\platform\logic\PlatformLogic;
use app\src\platform\logic\PlatformAdminLogic;
use app\web\api\WithdrawDepositApi;
use wordFilter\WordFilter;
class Extension extends Weixin
{
    protected function _initialize()
    {
        parent::_initialize();

        if (session("?memberinfo")) {
            $uid = $this->_param('uid','');
            $pwd = $this->_param('pwd','');
            if(!empty($pwd)&&!empty($uid)){
                $result = (new UcenterMemberLogic())->getInfo(['id' => $uid, 'password' => $pwd]);
                if ($result['status'] && !empty($result['info'])) {
                    $action = new LoginAction();
                    $result = $action->loginByUID($uid, 'device_id_um', 'pc', 'role_user');
                    if ($result['status']) {
                        session("memberinfo", $result['info']);
                        $this->memberinfo = session("memberinfo");
                    }
                } else {
                    $this->redirect('index/index');
                }
            }else{
                $this->memberinfo = session("memberinfo");
            }
        } else {
            $uid = $this->_param('uid');
            $pwd = $this->_param('pwd');
            $result = (new UcenterMemberLogic())->getInfo(['id' => $uid, 'password' => $pwd]);
            if ($result['status'] && !empty($result['info'])) {
                $action = new LoginAction();
                $result = $action->loginByUID($uid, 'device_id_um', 'pc', 'role_user');
                if ($result['status']) {
                    session("memberinfo", $result['info']);
                    $this->memberinfo = session("memberinfo");
                }
            } else {
                $this->redirect('index/index');
            }
        }
    }

    public function index()
    {
        $this->assignTitle('推广中心');
        //  dump(session("memberinfo"));exit;
        return $this->fetch();


    }


    //省级平台
    public function index_province()
    {
        $this->assignTitle('省管理中心');

        $uid = $this->memberinfo['uid'];

        $result = (new PlatformAdminLogic)->getAdminPlatform($uid,PlatformType::PROVINCE_SERVICE);

        if ($result['status'] && !empty($result['info'])) {
            if ($result['info'][0]['group_id'] == 3) {
                $this->assign('platform_id', $result['info'][0]['platform_id']);
                $this->assign('platform_type', 3);
                $this->assignTitle($result['info'][0]['name']);
                $result=SellerApi::countInfo($result['info'][0]['platform_id'],4);
                if($result['status']) {
                    $this->assign('countInfo', $result['info']);
                }

                return $this->fetch();
            }

        }
        return $this->fetch('extension/no_identity');
    }

    //添加市级平台
    public function add_city()
    {

        $this->assignTitle('添加城市服务中心');
        $platform_id = $this->_param('platform_id');
        $this->assign('platform_id', $platform_id);
        $platform_type = $this->_param('platform_type');
        $this->assign('platform_type', $platform_type);
        if (IS_POST) {
            $platform_id = $this->_param('platform_id');
            $group_id = 2;
            $city_name = $this->_param('city_name', '');
            $idcard_number = $this->_param('idcard_number', '');
            $bank_card_no = $this->_param('bank_card_no', '');
            $bank_card_name = $this->_param('bank_card_name', '');
            $mobile = $this->_param('mobile', '');
            $idcard_front = $this->_param('idcard_front', '');
            $idcard_back = $this->_param('idcard_back', '');
            $business_licence = $this->_param('business_licence', '');
            $account_mobile = $this->_param('account_mobile', '','账号缺失');
            $account_psw = $this->_param('account_psw', '','密码缺失');

            $result = PlatfromApi::addPlatform($platform_id,$group_id,$city_name,$idcard_number,$bank_card_no,$bank_card_name,$mobile,$idcard_front,$idcard_back,$business_licence,$account_mobile,$account_psw);
            if ($result['status']) {
                $this->success('添加成功', '', $result['info']);
            } else {
                $this->error('添加失败', '', $result['info']);
            }
        }
        return $this->fetch();
    }

    //编辑个人创业平台
    public function edit_city()
    {
        $this->assignTitle('编辑城市');

        $platform_id = $this->_param('platform_id');
        $result = (new PlatformLogic())->getInfo(['id'=>$platform_id]);
        if($result['status']&&!empty($result['info']['other_info'])){
            $person_info=json_decode($result['info']['other_info'],true);
         //   dump($person_info);exit;
        }else{
            $person_info=[];
        }
        $this->assign('city_info', $person_info);
        $this->assign('platform_id', $platform_id);
        return $this->fetch();
    }

//编辑个人创业平台
    public function edit_person()
    {
        $this->assignTitle('编辑创业伙伴');
        if (IS_POST) {
            $platform_id = $this->_param('platform_id');
            $platform_father= $this->_param('platform_father');
            if($this->_param('del')=='del'){
                $result = (new DeleteApplyLogic())->addApply(2,$platform_id,$platform_father);
                if($result['status']){
                    $this->success('已发起删除请求', '');
                }else{
                    $this->error('请求发起失败', '');
                }

            }

            $name = $this->_param('name', '');
            $mobile = $this->_param('mobile', '');
            $entity=array(
                 'name'=>$name,
                'mobile'=>$mobile
            );
            $result =  $result = (new PlatformLogic())->saveByID($platform_id, $entity);
            if ($result['status']) {
                $this->success('修改成功', '', $result['info']);
            } else {
                $this->error('修改失败', '', $result['info']);
            }
        }
        $platform_id = $this->_param('platform_id');
        $platform_type = $this->_param('platform_type');
        $platform_father = $this->_param('platform_father');
        $result = (new PlatformLogic())->getInfo(['id'=>$platform_id]);
        if($result['status']&&!empty($result['info']['other_info'])){
            $person_info=json_decode($result['info']['other_info'],true);
        }else{
            $person_info=[];
        }
    //    dump($person_info);exit;
        $this->assign('person_info', $person_info);
        $this->assign('platform_id', $platform_id);
        $this->assign('platform_father', $platform_father);
        $this->assign('platform_type', $platform_type);
        return $this->fetch();
    }

//市级平台列表
    public function added_city()
    {


        $platform_id = $this->_param('platform_id');
        $city_name = $this->_param('city_name');
        $this->assignTitle('城市服务中心列表');

        $map = [
            'parent_id' => $platform_id,
            'status' => 0
        ];
        $map['name']=array('like', "%$city_name%");
        $result = (new PlatformLogic())->queryNoPaging($map);
        $this->assign('platform_id', $platform_id);
        $this->assign('city_list', $result['info']);
        //  dump($result);exit;

        return $this->fetch();
    }


//市级平台
    public function index_city()
    {
        $this->assignTitle('城市服务中心');
        $uid = $this->memberinfo['uid'];

        $result = (new PlatformAdminLogic)->getAdminPlatform($uid,PlatformType::CITY_SERVICE);



        if ($result['status'] && !empty($result['info'])) {
            if ($result['info'][0]['group_id'] == 2) {
                $this->assign('platform_id', $result['info'][0]['platform_id']);
                $this->assign('platform_type', 2);
                $this->assignTitle($result['info'][0]['name']);
               // dump($result);exit;
                $result=SellerApi::countInfo($result['info'][0]['platform_id'],3);

                if($result['status']) {
                    $this->assign('countInfo', $result['info']);

                }

                return $this->fetch();
            }
        }
        return $this->fetch('extension/no_identity');
    }

    //添加创业伙伴
    public function add_person()
    {
        $this->assignTitle('添加创业伙伴');
        $platform_id = $this->_param('platform_id');
        $this->assign('platform_id', $platform_id);
        $platform_type = $this->_param('platform_type');
        $this->assign('platform_type', $platform_type);
        if (IS_POST) {
            $platform_id = $this->_param('platform_id');
            $group_id = 1;
            $name = $this->_param('name', '');
            $idcard_number = $this->_param('idcard_number', '');
            $bank_card_no = $this->_param('bank_card_no', '');
            $bank_card_name= $this->_param('bank_card_name', '');
            $mobile = $this->_param('mobile', '');
            $idcard_front = $this->_param('idcard_front', '');
            $idcard_back = $this->_param('idcard_back', '');
            $account_mobile = $this->_param('account_mobile', '','账号缺失');
            $account_psw = $this->_param('account_psw', '','密码缺失');

            $result = PlatfromApi::addPlatform2($platform_id,$group_id,$name,$idcard_number,$bank_card_no,$bank_card_name,$mobile,$idcard_front,$idcard_back,$account_mobile,$account_psw);
            if ($result['status']) {
                $this->success('添加成功', '', $result['info']);
            } else {
                $this->error('添加失败', '', $result['info']);
            }
        }
        return $this->fetch();
    }

//创业伙伴列表
    public function added_person()
    {


        $this->assignTitle('创业伙伴列表');
        $platform_id = $this->_param('platform_id');

        $platform_type = $this->_param('platform_type');
        $person_name = $this->_param('person_name');
        if ($platform_type == 2) {
            $map = [
                'parent_id' => $platform_id,
                'status' => 0
            ];
            $map['name']=array('like', "%$person_name%");
            $result = (new PlatformLogic())->queryNoPaging($map);
            if ($result['status']) {
                $this->assign('person_list', $result['info']);
                $this->assign('platform_type', $platform_type);
                $this->assign('platform_father', $platform_id);
            }
        } elseif ($platform_type == 3) {
            $personList = [];
            $map = [
                'parent_id' => $platform_id,
                'status' => 0
            ];
            $map['name']=array('like', "%$person_name%");
            $result = (new PlatformLogic())->queryNoPaging($map);
            if(!$result['status']) $this->error($result['info']);
            foreach ($result['info'] as $item) {
                if($item['status']==0){
                    $map = [
                        'parent_id' => $item['id'],
                        'status' => 0
                    ];
                    $result = (new PlatformLogic())->queryNoPaging($map);
                    if($result['status']){
                        foreach ($result['info'] as $val){
                            $personList[] = $val;
                        }
                    }
                }

            }

            $this->assign('person_list',$personList);
            $this->assign('platform_type', $platform_type);
            $this->assign('platform_father', $platform_id);
        }

        return $this->fetch();
    }


    //编辑商家
    public function edit_shop()
    {
        $this->assignTitle('编辑商家');
        if (IS_POST) {
            $seller_id = $this->_param('seller_id');
            $platform_father= $this->_param('platform_father');
            if($this->_param('del')=='del'){
               $result = (new DeleteApplyLogic())->addApply(1,$seller_id,$platform_father);
                if($result['status']){
                    $this->success('已发起删除请求', '');
                }else{
                    $this->error('请求发起失败', '');
                }

            }

            $name = $this->_param('name');
            $price = (float)$this->_param('price')*100;
            $scope = $this->_param('scope');
            $discount_rate = $this->_param('discount_rate');
            if((float)$discount_rate>=1){
                $this->error('折扣不能大于一', '');
            }
            $contact_number = $this->_param('contact_number');
            $logo = $this->_param('logo');
            $main_img = $this->_param('main_img');
            $main_img = json_decode($main_img);
            $main_img = implode(",",$main_img);
            $main_img_small = $this->_param('main_img_small');
            $category_id = $this->_param('category_id');
            $position = $this->_param('position');
            $ret = AddressHelper::getAddressPos($position);
            if($ret['status'] == 1){
                $this->error('获取商家经纬度失败');
            }else{
                $location = $ret['result']['location'];
                $lng = $location['lng'];
                $lat = $location['lat'];
            }
            $entity = array(
                'name' => $name,
                'price' => $price,
                'scope' => $scope,
                'discount_rate' => $discount_rate,
                'contact_number' => $contact_number,
                'logo' => $logo,
                'main_img' => $main_img,
                'main_img_small' => $main_img_small,
                'category_id' => $category_id,
                'lng'=>$lng,
                'lat'=>$lat,
                'position'=>$position
            );

            $result = (new SellerLogic())->updateSeller($seller_id, $entity);
            if ($result['status']) {
                $this->success('修改成功', '', $result['info']);
            } else {
                $this->error('修改失败', '', $result['info']);
            }
        }
        $seller_id = $this->_param('seller_id');
        $platform_type = $this->_param('platform_type');
        $platform_father= $this->_param('platform_father');
        $result = (new SellerLogic())->detailInfo($seller_id);

        $this->getAllCategory();
        //获取当前分类名称
        $seller_info =  $result['info']['seller'];
        $result = (new SellerCategoryLogic)->getSellerCategoryInfo($seller_info['category_id']);
        $cate_name = '无分类';
        if($result['status']){
            $cate_name = $result['info']['name'];
        }
        $this->assign('cate_name', $cate_name);

        $this->assign('shop_info', $seller_info);
        $main_img = explode(',',$seller_info['main_img']);
        $this->assign('main_img', $main_img);
        $this->assign('seller_id', $seller_id);
   //     dump($platform_id);exit;
        $this->assign('platform_father', $platform_father);
        $this->assign('platform_type', $platform_type);

        return $this->fetch();
    }
    public function del_shop()
    {

        return $this->fetch();
    }

    //创业伙伴
    public function index_person()
    {
        $this->assignTitle('创业伙伴');
        $uid = $this->memberinfo['uid'];

        $result = (new PlatformAdminLogic)->getAdminPlatform($uid,PlatformType::PERSONAL);


        //   dump($result['info'][0]);exit;
        if ($result['status'] && !empty($result['info'])) {
            if ($result['info'][0]['group_id'] == 1) {
                $this->assign('platform_id', $result['info'][0]['platform_id']);
                $this->assign('platform_type', 1);
                $this->assignTitle($result['info'][0]['name']);
                $result=SellerApi::countInfo($result['info'][0]['platform_id'],1);
                if($result['status']) {
                    $this->assign('countInfo', $result['info']);
                }
                return $this->fetch();
            }
        }
        return $this->fetch('extension/no_identity');
    }

    //添加商家
    public function add_shop()
    {
        $this->assignTitle('添加商家');
        if (IS_POST) {
            $platform_id = $this->_param('platform_id');
            $position = $this->_param('position');
            $name = $this->_param('name');
            $price = (float)$this->_param('price')*100;
            $scope = $this->_param('scope');
            $discount_rate = $this->_param('discount_rate');
            if((float)$discount_rate>=1){
                $this->error('折扣不能大于一', '');
            }
            $rack_back_rate = $this->_param('rack_back_rate');
            if((float)$rack_back_rate>=0.994){
                $this->error('分佣过高', '');
            }
            $contact_number = $this->_param('contact_number');
            $bank_card_name = $this->_param('bank_card_name');
            $pca = $this->_param('pca');
            $kh = $this->_param('kh');
            $bank_card_name = $pca.','.$bank_card_name.','.$kh;
            $bank_card_no = $this->_param('bank_card_user').':'.$this->_param('bank_card_no');
            $first_offer = $this->_param('first_offer');
            $first_offer_num = $this->_param('first_offer_num');
            $account_psw = $this->_param('account_psw','','密码缺失');
            $account_mobile = $this->_param('account_mobile','','账号缺失');
            $logo = $this->_param('logo');
            $main_img = $this->_param('main_img');
            $main_img = json_decode($main_img);
            $main_img = implode(",",$main_img);
            $main_img_small = $this->_param('main_img_small');
            $category_id = $this->_param('category_id');
            $result = SellerApi::addByPersonalPlatform($platform_id, $name, $price, $scope, $discount_rate,
                $rack_back_rate, $contact_number, $account_mobile, $first_offer, $account_psw, $logo, $main_img,
                $main_img_small, $position,$bank_card_name,$bank_card_no,$first_offer_num,$category_id);
            if ($result['status']) {
                $this->success('添加成功', '', $result['info']);
            } else {
                $this->error('添加失败', '', $result['info']);
            }
        }
        $this->getAllCategory();
        $platform_id = $this->_param('platform_id');
        $result = (new PlatformLogic)->getPlatformInfo($platform_id);
        if($result['status']){
            $this->assign('preferential_money', $result['info']['preferential_money']);
        }
        $this->assign('platform_id', $platform_id);
        return $this->fetch();
    }

//商家列表(市和个人共用)
    public function added_shop()
    {
        $this->assignTitle('商家列表');
        $platform_id = $this->_param('platform_id');

        $platform_type = $this->_param('platform_type');
        $shop_name = $this->_param('shop_name');
        if ($platform_type == 1) {
            $map = [
                'parent_id' => $platform_id,
                'status' => 0
            ];
            $map['name']=array('like', "%$shop_name%");
            $result = (new SellerLogic())->queryNoPaging($map);
            if($result['status']){
                foreach ($result['info'] as $val){
                    $shopList[] = $val;
                }
            }
            if ($result['status']) {
                $this->assign('shop_list', $result['info']);
                $this->assign('platform_type', 1);
                $this->assign('platform_id', $platform_id);
            }
        } elseif ($platform_type == 2) {
            $shopList = [];
            $result = (new PlatformLogic())->childAll($platform_id);
            if(!$result['status']) $this->error($result['info']);
            foreach ($result['info'] as $item) {
                if($item['status']==0){
                    $map = [
                        'parent_id' => $item['id'],
                        'status' => 0
                    ];
                    $map['name']=array('like', "%$shop_name%");
                    $result = (new SellerLogic())->queryNoPaging($map);
                    if($result['status']){
                        foreach ($result['info'] as $val){
                            $shopList[] = $val;
                        }
                    }
                }
            }
          // dump($shopList);exit;
            $this->assign('shop_list',$shopList);
            $this->assign('platform_type', 2);
            $this->assign('platform_id', $platform_id);
        }
        return $this->fetch();
    }


    //联盟商家
    public function index_shop()
    {

        $this->assignTitle('联盟商家');
        $uid = $this->memberinfo['uid'];
        $result = (new SellerLogic)->getInfo(['uid'=>$uid,'status'=>0]);
       // dump($result);
        if($result['status']&&!empty($result['info'])){
            $this->assign('seller_id', $result['info']['id']);
            $result=SellerApi::countInfo($result['info']['id'],2);
//dump($result);exit;
            if($result['status']) {
                $this->assign('countInfo', $result['info']);
            }
            return $this->fetch();
        }
        return $this->fetch('extension/no_identity');
    }
    //商家二维码
    public function shop_ewm()
    {


        $this->assignTitle('商家/二维码');
        $seller_id = $this->_param('seller_id');
        $result = (new SellerLogic)->getInfo(['id'=>$seller_id]);
        $code=InviteCodeApi::getCode('2',$seller_id);
        $SignPackage = $this->wxapi->getSignPackage();
        $this->assign('SignPackage', $SignPackage);
        $url = SITE_URL.url('shop/shopdetail',array('invite_code'=>$code['info']['invite_code'],'seller_id'=>$seller_id));
        $this->assign('invite_code', $code['info']['invite_code']);
        $this->assign('seller_info',$result['info']);
        $this->assign('url', $url);
      //  dump($result['info']);exit;
        return $this->fetch();
    }

    //添加优惠卷
    public function add_charge()
    {
        $this->assignTitle('添加优惠');
        if (IS_POST) {
            $seller_id = $this->_param('seller_id');
            $uid = $this->memberinfo['uid'];
            $title = $this->_param('title');
            $detail = $this->_param('detail');
            $img = $this->_param('img');
            $result = SellerApi::addPromotion('itboye', $seller_id, $uid, $title, $detail, $img);
          //  dump($result);exit;
            if ($result['status']) {
                $this->success('添加成功', '', $result['info']);
            } else {
                $this->error('添加失败', '', $result['info']);
            }
        }
        $seller_id = $this->_param('seller_id');
        $this->assign('seller_id', $seller_id);
        return $this->fetch();
    }

//优惠卷列表
    public function added_charge()
    {
        $seller_id = $this->_param('seller_id');;

        $this->assignTitle('优惠折扣');
        $map=[
            'seller_id'=>$seller_id,
            'status'=>0
        ];
        $result=(new SellerPromotionLogic())->queryNoPaging($map);
        $this->assign('promotion_list', $result['info']);
      //  dump($result);exit;
        return $this->fetch();
    }

    //编辑优惠
    public function edit_charge()
    {

        if (IS_POST) {
            if($this->_param('del')=='del'){
                $seller_id = $this->_param('seller_id');
                $promotion_id = $this->_param('promotion_id');
                $entity = array(
                    'status' => -1,
                );
                $result = (new SellerPromotionLogic)->updatePromotion($seller_id,$promotion_id,$entity);
                if ($result['status']) {
                    $this->success('删除成功', '', $result['info']);
                } else {
                    $this->error('删除失败', '', $result['info']);
                }
            }
            $promotion_id = $this->_param('promotion_id');
            $seller_id = $this->_param('seller_id');
            $title = $this->_param('title');
            $detail = $this->_param('detail');
            $detail = (new WordFilter)->filter($detail);
            $title = (new WordFilter)->filter($title);
            $img = $this->_param('img');
           $entity=array(
               'title'=>$title,
               'detail'=>$detail,
               'img'=>$img
            );
            $result = (new SellerPromotionLogic)->updatePromotion($seller_id,$promotion_id,$entity);
            if ($result['status']) {
                $this->success('编辑成功', '', $result['info']);
            } else {
                $this->error('添加失败', '', $result['info']);
            }
        }
        $this->assignTitle('编辑优惠');
        $seller_id = $this->_param('seller_id');
        $promotion_id = $this->_param('promotion_id');
        $this->assign('seller_id', $seller_id);
        $this->assign('promotion_id', $promotion_id);
        $result = (new SellerPromotionLogic)->getInfo(['id'=>$promotion_id]);
//     dump($result);exit;

        $this->assign('promotion_info', $result['info']);
        return $this->fetch();
    }

    //商家详情
    public function shopdetail_edit()
    {

        if (IS_POST) {
            $seller_id = $this->_param('seller_id');
            $title = $this->_param('title');
            $detail = $this->_param('detail');
            $detail = (new WordFilter)->filter($detail);
            $title = (new WordFilter)->filter($title);
            $img = $this->_param('img');
            $arr = array(
                'title'=>$title,
                'detail'=>$detail,
                'img'=>$img
            );
            $entity['detail'] = json_encode($arr,256);
            $result = (new SellerLogic)->updateSeller($seller_id,$entity);
            if ($result['status']) {
                $this->success('编辑成功', '', $result['info']);
            } else {
                $this->error('添加失败', '', $result['info']);
            }
        }
        $this->assignTitle('商家详情编辑');
        $seller_id = $this->_param('seller_id');
        $this->assign('seller_id', $seller_id);
        $result = (new SellerLogic)->getInfo(['id'=>$seller_id]);
        if($result['status']&&!empty($result['info']['detail'])){
            $detail =  json_decode($result['info']['detail'],true);
            $img = explode(',',$detail['img']);
            $img = array_filter($img);
            $this->assign('detail', $detail);
            $this->assign('img',$img);
        }else{
            $this->assign('img',[]);
            $this->assign('detail', []);
        }



        return $this->fetch();
    }


    public function index_dxe()
    {

        $this->assignTitle('我是店长');
        $uid = $this->memberinfo['uid'];
        $result = (new SellerLogic())->getInfo(['waiter_id'=>$uid,'status'=>0]);
        if(!$result['status'])  $this->error('数据库查询错误', '', $result['info']);
        if(!empty($result['info'])){
            $result=SellerApi::countInfo($uid,5);
            if($result['status']) {
                $this->assign('countInfo', $result['info']);
            }
            return $this->fetch();
        }else{
            return $this->fetch('extension/no_identity');
        }

    }

    public function add_dxe()
    {
        $seller_id = $this->_param('seller_id');

        $this->assignTitle('添加店长');
        if (IS_POST) {
            if(!empty($this->_param('del'))&&$this->_param('del')=='del'){
                $waiter_id=$this->_param('waiter_id');
                if(empty($waiter_id)){
                    $this->error('该商家不存在店小二', '');
                }
                $result = (new SellerLogic())->removeWaiter($seller_id,$waiter_id);
                if ($result['status']) {
                    $this->success('删除成功', '', $result['info']);
                } else {
                    $this->error('删除失败', '', $result['info']);
                }
            }
            $account = $this->_param('account');
            $uinfo = (new UcenterMemberLogic())->getInfo(['mobile' => $account]);
            if ($uinfo['status']&&!empty($uinfo['info'])) {
                $result = (new SellerLogic())->setWaiter($seller_id, $uinfo['info']['id']);
                if ($result['status']) {
                    $this->success('添加成功', '', $result['info']);
                } else {
                    $this->error('添加失败', '', $result['info']);
                }
            } else {
                $this->error('未注册号码', '');
            }

        }
        $this->assign('seller_id', $seller_id);
        $result = (new SellerLogic())->getInfo(['id'=>$seller_id]);
        if($result['status']&&!empty($result['info'])){
            if(!empty($result['info']['waiter_id'])){
                $uinfo = (new UcenterMemberLogic())->getInfo(['id' => $result['info']['waiter_id']]);
                if($uinfo['status']&&!empty($uinfo['info'])){
                    $this->assign('waiter_id',$result['info']['waiter_id']);
                    $this->assign('mobile',$uinfo['info']['mobile']);
                }
            }else{
                $this->assign('waiter_id','');
                $this->assign('mobile','');
            }

        }
        return $this->fetch();
    }


    public function commission_details()
    {
        $page = $this->_param('page');
        $account_id = $this->_param('account_id');
        $role_type = $this->_param('role_type');
        $charge_type = $this->_param('type');
        $result=AccountScoreApi::getAccounts($account_id,$role_type,$page,10,$charge_type);
        if ($result['status']) {
            $this->success('数据获取成功', '', $result['info']['list']);
        } else {
            $this->error('数据获取失败', '', $result['info']);
        }
        return $this->fetch();
    }

    public function commission_list()
    {
        $this->assignTitle('佣金明细');
        if(!empty($this->_param('seller_id'))){
            $account_id = $this->_param('seller_id');
            $type = '2';
            $result=AccountScoreApi::getInfo($type,$account_id);
            if($result['status']) {
                $this->assign('score', $result['info']['score1']);

            }
        }else{
            $account_id = $this->_param('platform_id');
            $type = '1';
            $result=AccountScoreApi::getInfo($type,$account_id);
            if($result['status']) {
                $this->assign('score', $result['info']['score1']);
            }
        }
        $this->assign('account_id', $account_id);
        $this->assign('type', $type);
        return $this->fetch();
    }

    public function tixian(){
        $this->assignTitle('提现');
        if (IS_POST) {
            $account_id = $this->_param('account_id');
            $score = $this->_param('score');
            $score = $score*100;
            $account_type = $this->_param('account_type');
            $bank_card_no = $this->_param('bank_card_no');
            $mobile = $this->_param('mobile');
            $name = $this->_param('name');
            $pca = $this->_param('pca');
            $kh = $this->_param('kh');
            $bank_card_name = $this->_param('bank_card_name');
            $bank_card_name = $pca.','.$bank_card_name.','.$kh;
            $result =  WithdrawDepositApi::apply($account_id,$score,$bank_card_no,$bank_card_name,$account_type,$mobile,$name);
            if ($result['status']) {
                $this->success('申请成功', '', $result['info']);
            } else {
                $this->error('申请失败', '', $result['info']);
            }
        }
        $account_type = $this->_param('account_type');
        $account_id = $this->_param('account_id');
        $result=AccountScoreApi::getInfo($account_type,$account_id);
        if($result['status']) {
            $this->assign('score', $result['info']['score1']);
        }
        $this->assign('account_id', $account_id);
        $this->assign('account_type', $account_type);
        return $this->fetch();
    }

    public function shop_consumption(){
        $this->assignTitle('消费记录');
        $seller_id = $this->_param('seller_id');
        $result=SellerApi::countInfo($seller_id,2);
        if($result['status']) {
            $this->assign('countInfo', $result['info']);
        }
        $this->assign('seller_id', $seller_id);
        return $this->fetch();
    }
    public function shop_consumption2(){
        $this->assignTitle('商家运营');
        $seller_id = $this->_param('seller_id');
        $n = mktime(14,0,0,date('m'),date('d'),date('Y'));
        $y = mktime(14,0,0,date('m'),date('d')-1,date('Y'));
        $map=[
            'seller_id'=>$seller_id,
            'order_status'=>1,
            'pay_time'=>[['>=', $y], ['<', $n]]
        ];

        $result = (new SellerOrderLogic)->queryNoPaging($map);
        $income = (new SellerOrderLogic)->sum($map,'income');
        $seller = (new SellerLogic())->getInfo(['id'=>$seller_id]);
        if($result['status']) {
            $this->assign('income', $income['info']);
            $this->assign('seller', $seller['info']);
            $this->assign('info', $result['info']);
        }
        $this->assign('seller_id', $seller_id);
        return $this->fetch();
    }

    public function shop_consumption_data(){
        $page_index = $this->_param('page','1');
        $page = ['curpage'=>$page_index,'size'=>10];
        $seller_id = $this->_param('seller_id');
        $map=['seller_id'=>$seller_id];$map['order_status']=1;
        $order = " create_time desc ";
        $result=(new SellerOrderLogic)->queryWithPagingHtml($map,$page,$order);
        if($result['status']){
            $this->success('数据获取成功', '', $result['info']['list']);
        }else{
            $this->error('数据获取失败', '', $result['info']);
        }
        return $this->fetch();
    }

    /**
     * 获取商家类目
     */
    protected function getAllCategory()
    {
        $result = SellerApi::queryAllCategory();
        if($result['status']){
            $list =  [];
            $baseImgUrl = SITE_URL.'/static/web/img';
            foreach ($result['info'] as $val){

                if($val['id'] == 1){
                    $list[] = [
                        'caption' => $val['name'],
                        'cateId' => intval($val['id']),
                        'normal'  => $baseImgUrl . '/shopCategory/meishi_normal.png',
                        'hover'  => $baseImgUrl . '/shopCategory/meishi_hover.png',
                        'checked' => true,
                        'children' => $val['children']
                    ];
                }
                if($val['id'] == 2){
                    $list[] = [
                        'caption' => $val['name'],
                        'cateId' => intval($val['id']),
                        'normal'  => $baseImgUrl . '/shopCategory/yule_normal.png',
                        'hover'  => $baseImgUrl . '/shopCategory/yule_hover.png',
                        'checked' => false,
                        'children' => $val['children']
                    ];
                }
                if($val['id'] == 3){
                    $list[] = [
                        'caption' => $val['name'],
                        'cateId' => intval($val['id']),
                        'normal'  => $baseImgUrl . '/shopCategory/yifu_normal.png',
                        'hover'  => $baseImgUrl . '/shopCategory/yifu_hover.png',
                        'checked' => false,
                        'children' => $val['children']
                    ];
                }
                if($val['id'] == 4){
                    $list[] = [
                        'caption' => $val['name'],
                        'cateId' => intval($val['id']),
                        'normal'  => $baseImgUrl . '/shopCategory/lvxing_normal.png',
                        'hover'  => $baseImgUrl . '/shopCategory/lvxing_hover.png',
                        'checked' => false,
                        'children' => $val['children']
                    ];
                }

            }
            foreach ($list as &$val){
                $children = [];
                foreach ($val['children'] as $val2){
                    $children2 = [];
                    foreach ($val2['children'] as $val3){
                        $children2[] = [
                            'name' => $val3['name'],
                            'shop_number' => $val3['count'],
                            'cateId' => intval($val3['id']),
                            'icon' => getImgUrl($val3['icon'],120)
                        ];
                    }
                    $children[] = [
                        'name' => $val2['name'],
                        'shop_number' => $val2['count'],
                        'cateId' => intval($val2['id']),
                        'children' => $children2
                    ];
                }
                $val['children'] = $children;
            }

            $this->assign('category',json_encode($list, JSON_UNESCAPED_UNICODE));
        }
    }

}